package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.GgYhxx;
import com.example.demo.mapper.GgYhxxMapper;
import com.example.demo.vo.YhxxVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @description:  公共用户信息控制台
* @author: zhouzhong
* @date: 2021/06/07 18:39
* @path: com.example.demo.controller.GgYhxxController
* @version: 1.0
*/

//@Controller
//@ResponseBody
@RestController
@RequestMapping(value = "/yhxx")
public class GgYhxxController {
    @Autowired
    private GgYhxxMapper ggYhxxMapper;



    /**
     * BaseMapper自带的录入方法
     * http://localhost:6358/yhxx/insert
     */
    @RequestMapping("/insert")
    public boolean insert(){
        GgYhxx ggYhxx = new GgYhxx();
        ggYhxx.setId("000001");
        ggYhxx.setYhid("000001");
        ggYhxx.setYhlx("02");
        ggYhxx.setYhmc("demo");
        ggYhxx.setYhzt("1");
        int bl =ggYhxxMapper.insert(ggYhxx);
        System.out.println("insert:"+bl);
        return true;
    }



    /**
     * BaseMapper自带的修改方法
     * http://localhost:6358/yhxx/update
     */
    @RequestMapping("/update")
    public boolean update(){
        GgYhxx ggYhxx = new GgYhxx();
        ggYhxx.setYhlx("02");
        ggYhxx.setYhmc("demo001");
        ggYhxx.setYhzt("1");
        QueryWrapper<GgYhxx> wrapper = new QueryWrapper<>();
        wrapper.eq("id","000001");
        int bl =ggYhxxMapper.update(ggYhxx,wrapper);
        System.out.println("update:"+bl);
        return true;
    }



    /**
     * BaseMapper自带的删除方法
     * http://localhost:6358/yhxx/delete
     */
    @RequestMapping("/delete")
    public boolean delete(){
        QueryWrapper<GgYhxx> wrapper = new QueryWrapper<>();
        wrapper.eq("id","000001");
        int bl =ggYhxxMapper.delete(wrapper);
        System.out.println("delete:"+bl);
        return true;
    }



    /**
     * BaseMapper自带的分页查询
     * http://localhost:6358/yhxx/selectPage
     */
    @RequestMapping("/selectPage")
    public Page<GgYhxx> selectPage(){
        QueryWrapper<GgYhxx> wrapper = new QueryWrapper<>();
        Page<GgYhxx> page = new Page<GgYhxx>(1, 10);
        page = ggYhxxMapper.selectPage(page,wrapper);
        return page;
    }



    /**
     * 分页多表查询
     * http://localhost:6358/yhxx/selectPageAll
     */
    @RequestMapping("/selectPageAll")
    public Page<YhxxVo> selectPageAll(){
        QueryWrapper<YhxxVo> wrapper = new QueryWrapper<>();
        wrapper.eq("yhzt","1");
        Page<YhxxVo> page = new Page<YhxxVo>(1, 10);
        List<YhxxVo> list = ggYhxxMapper.searchYhxxList(page,wrapper);
        page.setRecords(list);
        return page;
    }
}
